﻿using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WucCloud.Utility
{
    /// <summary>
    /// Api常用返回结果帮助类
    /// </summary>
    public static class ApiResultHelper
    {
        /// <summary>
        /// 成功后返回的数据
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public static ApiResult Success(object data)
        {
            return new ApiResult
            {
                code = 200,
                msg = "操作成功",
                data = data,
                count = 10000
            };
        }

        /// <summary>
        /// 成功后返回的数据  带分页
        /// </summary>
        /// <param name="data"></param>
        /// <param name="total"></param>
        /// <returns></returns>
        public static ApiResult Success(object data, RefAsync<int> total)
        {
            return new ApiResult
            {
                code = 200,
                msg = "操作成功",
                count = total,
                data = data,
            };
        }

        /// <summary>
        /// 失败后返回错误提示
        /// </summary>
        /// <param name="msg"></param>
        /// <returns></returns>
        public static ApiResult Error(string msg)
        {
            return new ApiResult
            {
                code = 500,
                msg = msg,
                data = null,
                count = 0
            };
        }
    }
}
